package com.platform.common.config.schedule;

import com.platform.common.utils.SpringUtil;
import org.quartz.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


/**
 * @author prngshuiming
 * @date: 2018/6/14 18:48
 */
public class SceduleLoad {


    Logger logger = LoggerFactory.getLogger(SceduleLoad.class);
    public void init() throws ClassNotFoundException, SchedulerException, InterruptedException {
        Scheduler scheduler = (Scheduler) SpringUtil.getBeanByClass(Scheduler.class);
        logger.info("初始化定时任务");
        scheduler.start();
        logger.info("开始定时任务");
        //具体任务.通过类路径新建任务
        JobDetail jobDetail = JobBuilder.newJob((Class<Job>) Class.forName("com.platform.web.provider.Schedule.HelloJob")).withIdentity("job1","group1").build();
        SimpleScheduleBuilder simpleScheduleBuilder = SimpleScheduleBuilder.simpleSchedule().withIntervalInSeconds(5).repeatForever();
        Trigger trigger = TriggerBuilder.newTrigger().withIdentity("trigger1","group1").startNow().withSchedule(simpleScheduleBuilder).build();
        // 交由Scheduler安排触发
        scheduler.scheduleJob(jobDetail,trigger);
//        scheduler.shutdown();//关闭定时任务调度器.
        logger.info("结束定时任务");
    }
}
